package com.bluesky.plum.uimodels.render.html;

import com.bluesky.javawebbrowser.domain.html.tags.Tag;
import com.bluesky.plum.uimodels.render.html.components.HButton;
import com.bluesky.plum.uimodels.render.html.components.HCheckBox;
import com.bluesky.plum.uimodels.render.html.components.HDateTimePicker;
import com.bluesky.plum.uimodels.render.html.components.HLabel;
import com.bluesky.plum.uimodels.render.html.components.HListBox;
import com.bluesky.plum.uimodels.render.html.components.HSpinBox;
import com.bluesky.plum.uimodels.render.html.components.HTable;
import com.bluesky.plum.uimodels.render.html.components.HTextArea;
import com.bluesky.plum.uimodels.render.html.components.HTextBox;
import com.bluesky.plum.uimodels.render.html.components.containers.HPanel;
import com.bluesky.plum.uimodels.render.html.components.containers.layout.HGrid;
import com.bluesky.plum.uimodels.render.html.components.containers.layout.HHorizontalBox;
import com.bluesky.plum.uimodels.render.html.components.containers.layout.HVerticalBox;
import com.bluesky.plum.uimodels.render.html.components.containers.window.HDialog;
import com.bluesky.plum.uimodels.render.html.components.containers.window.HMainWindow;
import com.bluesky.plum.uimodels.render.html.components.menu.HMenu;
import com.bluesky.plum.uimodels.render.html.components.menu.HMenuBar;
import com.bluesky.plum.uimodels.render.html.components.menu.HMenuItem;
import com.bluesky.plum.uimodels.standard.StandardUIComponentBuilder;
import com.bluesky.plum.uimodels.standard.StandardUIComponentType;
import com.bluesky.plum.uimodels.standard.UIComponent;
import com.bluesky.plum.uimodels.standard.UIComponentBuilder;
import com.bluesky.plum.uimodels.standard.components.ObjectEditor;
import com.bluesky.plum.uimodels.standard.components.containers.form.Form;
import com.bluesky.plum.uimodels.standard.components.objectBrowser.ObjectSelector;

public class HTMLUIComponentBuilder extends StandardUIComponentBuilder
		implements UIComponentBuilder {

	@Override
	protected void register() {
		super.register();
		
		componentTypeMap.put(StandardUIComponentType.Checkbox, HCheckBox.class);
		componentTypeMap.put(StandardUIComponentType.SpinBox, HSpinBox.class);
		componentTypeMap.put(StandardUIComponentType.TextBox, HTextBox.class);
		componentTypeMap.put(StandardUIComponentType.DateTimePicker,
				HDateTimePicker.class);
		componentTypeMap.put(StandardUIComponentType.ObjectBrowser,
				ObjectSelector.class);
		componentTypeMap.put(StandardUIComponentType.ObjectEditor,
				ObjectEditor.class);
		
		//nonfield component
		componentTypeMap.put(StandardUIComponentType.ListBox, HListBox.class);
		componentTypeMap.put(StandardUIComponentType.Table, HTable.class);
		

		componentTypeMap.put(StandardUIComponentType.Label, HLabel.class);
		componentTypeMap.put(StandardUIComponentType.TextArea, HTextArea.class);
		
		componentTypeMap.put(StandardUIComponentType.Button, HButton.class);
		componentTypeMap.put(StandardUIComponentType.Menu, HMenu.class);
		componentTypeMap.put(StandardUIComponentType.MenuItem, HMenuItem.class);
		componentTypeMap.put(StandardUIComponentType.MenuBar, HMenuBar.class);
		componentTypeMap.put(StandardUIComponentType.MainWindow, HMainWindow.class);
		componentTypeMap.put(StandardUIComponentType.Dialog, HDialog.class);
		componentTypeMap.put(StandardUIComponentType.Panel, HPanel.class);
		componentTypeMap.put(StandardUIComponentType.Form, Form.class);
		
		//layout
		componentTypeMap.put(StandardUIComponentType.HorizontalBox, HHorizontalBox.class);
		componentTypeMap.put(StandardUIComponentType.VerticalBox, HVerticalBox.class);
		componentTypeMap.put(StandardUIComponentType.Grid, HGrid.class);
	}

	
	@Override
	protected void afterCreateInstance(UIComponent uic) {
		Tag tag =TemplateUtil.getTag(uic.getComponentType().toString());
		if(tag!=null)
			uic.setTemplate(tag.toHtml());
	}
}
